package com.project.collectAPI.config;

import com.project.collectAPI.comm.Escape;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class MyInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("请求的Uri资源*************************:"+request.getRequestURL());
       /* System.out.println("拦截前:==============>"+request.getParameterMap());
        Map<String, String[]> mapparams = request.getParameterMap();
        Set<String> keySet = mapparams.keySet();
        // 遍历存放所有key的Set集合
        Iterator<String> it = keySet.iterator();
        System.out.println("是否有集合"+it.hasNext());
        while(it.hasNext()){ // 利用了Iterator迭代器**
            // 得到每一个key
            String key = it.next();
            // 通过key获取对应的value
            String[] value = mapparams.get(key);
            System.out.println("key = " +key);
            for(int i=0; i< value.length; i++)
            {
                System.out.println(key + " = " + value[i]);
            }
        }
        return false;*/
        return true;
    }





    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        //HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
        //System.out.println("请求的Uri后$$$$$$$$$$$$$$$$$$$:"+request.getRequestURL());
        /*System.out.println("拦截器监控完成请求:"+request.getParameterMap());
        Map<String, String[]> mapparams = request.getParameterMap();
        Set<String> keySet = mapparams.keySet();

        // 遍历存放所有key的Set集合
        Iterator<String> it = keySet.iterator();
        System.out.println("是否有集合"+it.hasNext());
        while(it.hasNext()){ // 利用了Iterator迭代器**
            // 得到每一个key
            String key = it.next();
            // 通过key获取对应的value
            String[] value = mapparams.get(key);
            System.out.println("key = " +key);
            for(int i=0; i< value.length; i++)
            {
                System.out.println(key + " = " + value[i]);
            }
        }*/
    }


    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        //HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
        //System.out.println("服务器返回"+ Escape.unescape(request.getParameter("form")));
    }


}
